//
//  LZTStatusRetweetview.swift
//  LZTWeibo
//
//  Created by Yin jianxun on 16/8/13.
//  Copyright © 2016年 YinJianxun. All rights reserved.
//

import UIKit
import SnapKit

//转发微博
class LZTStatusRetweetview: UIView {
    
    //记录 转发微博底部约束
    var retweetViewBottomContraint: Constraint?
    
    var statusViewModel: LZTStatusViewModel? {
        
        didSet{
            //假数据
            contentLabel.attributedText = statusViewModel?.retweetAttr
            
            //卸载 约束
            retweetViewBottomContraint?.uninstall()
            if statusViewModel?.statusModel?.retweeted_status?.pic_urls?.count > 0 {
                //有配图
                //赋值
                pictureView.pictureInfos = statusViewModel?.statusModel?.retweeted_status?.pic_urls
                //更新约束
                self.snp_makeConstraints { (make) in
                    retweetViewBottomContraint = make.bottom.equalTo(pictureView).offset(10).constraint
                }
                //显示配图控件
                pictureView.hidden = false
                
            } else {
                
                //没有配图
                //更新约束
                self.snp_makeConstraints { (make) in
                    retweetViewBottomContraint = make.bottom.equalTo(contentLabel).offset(10).constraint
                }
                //隐藏配图控件
                pictureView.hidden = true
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() {
        
        backgroundColor = RGB(237, green: 237, blue: 237)
        
        //添加控件
        addSubview(contentLabel)
        addSubview(pictureView)
        //添加约束
        contentLabel.snp_makeConstraints { (make) in
            make.leading.top.equalTo(10)
        }
        
        pictureView.snp_makeConstraints { (make) in
            make.top.equalTo(contentLabel.snp_bottom).offset(10)
            make.size.equalTo(CGSize(width: 100, height: 100))
            make.leading.equalTo((SCREENW - 250) * 0.5)
        }
        
        self.snp_makeConstraints { (make) in
            //默认都有配图，上面会根据pic的count进行判断显示与否
            retweetViewBottomContraint = make.bottom.equalTo(pictureView).offset(10).constraint
        }
    
    }
    
    //懒加载 控件
    private lazy var contentLabel: UILabel = UILabel(textColor: UIColor.darkGrayColor(), textSize: 15, maxWidth: SCREENW - 20)
    
    //懒加载 配图
    private lazy var pictureView: LZTStatusPictureView = LZTStatusPictureView()
    
}
